<%@ Page Language="C#" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<html>
<head>
    <title>Emoticon</title>
</head>
<body>
    <form id="StartPage" method="post" runat="server">
        <table border="1" style="border-collapse: collapse" width="100%">
            <tr>
                <%
                    string text = "";
                    StreamReader str = new StreamReader(Server.MapPath("/Images/EmoticonOng/EmoticonOng.txt"));
                    int iCount = 0;
                    while (!str.EndOfStream)
                    {
                        iCount++;
                        text = str.ReadLine();
                %>
                <td align="center">
                    <img style="cursor: hand" src="/Images/EmoticonOng/<% = text.Split(' ')[0] %>.png"
                        alt="<% = text.Split(' ')[0]  %>" onclick="doInsert('<% = HttpUtility.HtmlEncode(text.Split(' ')[1].ToString())%>')"></img>
                </td>
                <td align="center">
                    <% = HttpUtility.HtmlEncode(text.Split(' ')[1].ToString())%>
                </td>
                <%

                    if (iCount % 5 == 0)
                    {
                %>
            </tr>
            <tr>
                <%}
              }  %>
            </tr>
        </table>

        <script language="Javascript" type="text/javascript">
        function doInsert(smilieface)
        {
        	try
        	{
	            var ctrID = window.opener.document.getElementById("hidEmoticon").value;
	            var ctr = window.opener.document.getElementById(ctrID);	            
		        if (ctr != null && ctr.createTextRange && ctr.caretPos) 
		        {
			        var caretPos = ctr.caretPos;
			        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? smilieface + ' ' : smilieface;	
		        }
		        else 
		        {
			        ctr.value += smilieface
		        }
	        }
	        catch(e)
	        {
	        	alert(e.message);
	        }
	        window.close();
        }

        </script>

    </form>
</body>
</html>
